﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.Mobile.Configuration;
using System.Xml.Linq;

namespace ConfigurationGettingStarted
{
    class AppSettings : ConfigurationSection
    {
        private Dictionary<string, string> settings = new Dictionary<string, string>();
        protected override void DeserializeElement(System.Xml.XmlReader xml)
        {
            XElement x = XElement.Parse(xml.ReadOuterXml());
            var pairs = from nameval in x.Elements("add")
                        select new { Key = nameval.Attribute("key").Value, Value = nameval.Attribute("value").Value };
            foreach (var item in pairs)
            {
                settings[item.Key] = item.Value;
            }
        }

        public string this[string key]{
            get
            {
                return settings[key];
            }
        }
    }
}
